/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.IntConsumer;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * <p>Project: javase - Stream1
 * <p>Powered by webrx On 2021-12-22 11:33:44
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream1 {
    public static void main(String[] args) {
        System.out.println(IntStream.generate(() -> 5).limit(3).sum());
        System.out.println(IntStream.generate(() -> 5).limit(4).count());

        IntConsumer ic = System.out::println;

        ic.accept(13);
        IntStream.generate(() -> 5).limit(5).forEach(ic);

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(11);
        list.add(111);

        Stream<Integer> si = list.stream();
        //si.forEach(System.out::println);

        //System.out.println(si.count());
        //求和 a + b c + b
        System.out.println(si.reduce(Integer::sum).isPresent());

        Optional<Integer> op = Optional.empty();
        if (op.isPresent()) System.out.println(op.get());

        System.out.println(IntStream.range(1, 4).reduce((a, b) -> a * b).getAsInt());
    }
}
